package com.nexttwist.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SqlLiteHelper extends SQLiteOpenHelper {

	public static final String TABLE_TRACK = "tracks";
	public static final String TABLE_COMMENT = "comments";

	private static final String DATABASE_NAME = "nexttwist.db";
	private static final int DATABASE_VERSION = 2;

	// Database creation sql statement
	private static final String CREATE_TRACK = "CREATE TABLE "
			+ TABLE_TRACK
			+ " ( trackId integer primary key autoincrement,  trackUrl text not null,  title text not null,  album text not null,  vote integer not null,  userId integer not null);";

	private static final String CREATE_COMMENTS = "CREATE TABLE "
			+ TABLE_COMMENT
			+ " ( commentId integer primary key autoincrement,  trackId integer not null,  comment text not null, userId integer not null);";

	public SqlLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(CREATE_TRACK);
		database.execSQL(CREATE_COMMENTS);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(SqlLiteHelper.class.getName(), "Upgrading database from version "
				+ oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_TRACK);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENT);
		onCreate(db);
	}

}
